package com.nchuAo.controller;

import com.nchuAo.util.PageResult;
import com.nchuAo.util.Response;
import com.nchuAo.entity.Student;
import com.nchuAo.service.StudentService;
import com.nchuAo.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private StudentService studentService;

	// 学生列表
	@RequestMapping("/list")
	public Response getStudent() {
		return Response.ok().data("list",studentService.list());
	}

	// 分页查询
	@GetMapping("/findByPage/{page}/{pageSize}")
	public Response findByPage(@PathVariable("page") Integer page,
							   @PathVariable("pageSize") Integer pageSize) {
		PageResult<Student> pageResult = studentService.findByPage(page,pageSize);
		return Response.ok().data("pageResult",pageResult);
	}
	// 条件带分页查询
	@PostMapping("/search/{page}/{pageSize}")
	public Response search(@PathVariable("page") Integer page,
						   @PathVariable("pageSize") Integer pageSize,
						   @RequestBody(required = false) StudentVO vo){
		PageResult<Student> pageResult = studentService.search(page,pageSize,vo);
		return Response.ok().data("pageResult",pageResult);
	}
}
